package com.ruoyi.wechat.api;

import com.google.zxing.WriterException;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wechat.domain.Goods;
import com.ruoyi.wechat.service.IGoodsService;
import com.ruoyi.wechat.service.IQRCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 商品管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/wechat/goods")
public class WxGoodsController extends BaseController
{
    @Autowired
    private IQRCodeService qrCodeService;
    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询商品管理列表
     */
    @GetMapping("/list")
    public AjaxResult list(Goods goods)
    {
        List<Goods> list = goodsService.selectGoodsList(goods);
        return success(list);
    }

    /**
     * 新增商品管理
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Goods goods)
    {
        return toAjax(goodsService.insertGoods(goods));
    }

    //    生成二维码
    @Anonymous
    @GetMapping("/generateQRCode")
    public void generateQRCode(@RequestParam String text, HttpServletResponse response) throws WriterException, IOException {
        qrCodeService.generateQRCodeImage(text, response);
    }

}
